package com.bigger.controller;

import com.bigger.dto.EmployeePageDTO;
import com.bigger.dto.UpdateEmplDTO;
import com.bigger.entity.Employee;
import com.bigger.result.PageResult;
import com.bigger.result.Result;
import com.bigger.service.EmployeeService;
import com.bigger.vo.WagesVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/employee")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;

    @GetMapping("/get")
    public Result<PageResult<Employee>> pageQuery(EmployeePageDTO employeePageDTO){
        PageResult<Employee> pageResult=employeeService.page(employeePageDTO);
        return Result.success(pageResult);
    }

    @PostMapping("/add")
    public Result<String> addEmpl(@RequestBody UpdateEmplDTO updateEmplDTO){
        employeeService.addEmpl(updateEmplDTO);
        return Result.success("添加成功");
    }

    @PutMapping("/update")
    public Result<String> update(@RequestBody UpdateEmplDTO updateEmplDTO){
        employeeService.updateEmpl(updateEmplDTO);
        return Result.success("修改成功");
    }

    @DeleteMapping("/delete")
    public Result<String> delete(@RequestParam Long id){
        employeeService.deleteEmpl(id);
        return Result.success("删除成功");
    }

    @GetMapping("/get/{id}")
    public Result<Employee> getById(@PathVariable("id") Long id){
        Employee employee=employeeService.getById(id);
        employee.setPassword("******(嘿嘿嘿我也不知道啊)");
        return Result.success(employee);
    }

    @GetMapping("/wages")
    public Result<List<WagesVO>> wages(){
        List<WagesVO> wagesVOList=employeeService.wages();
        return Result.success(wagesVOList);
    }
}
